const Sequelize = require('sequelize')
const sequelize = require('../libs/db')
class ballot extends Sequelize.Model {}
ballot.init(
  {
    ballotId: {
      field: 'id',
      type: Sequelize.BIGINT,
      primaryKey: true,
      autoIncrement: true
    },
    optionId: {
      field: 'option_id',
      type: Sequelize.BIGINT,
      allowNull: true,
      defaultValue: 0,
      comment: '关联的投票选项ID'
    },
    userId: {
      field: 'user_id',
      type: Sequelize.BIGINT,
      allowNull: true,
      defaultValue: 0,
      comment: '关联的投票人ID'
    },
    description: {
      field: 'description',
      type: Sequelize.TEXT,
      comment: '投票描述'
    },
    status: {
      field: 'status',
      type: Sequelize.SMALLINT,
      allowNull: true,
      comment: '上下架状态,int。1-上架；0-下架'
    },
    createdAt: {
      field: 'created_at',
      type: Sequelize.BIGINT
    },
    updatedAt: {
      field: 'updated_at',
      type: Sequelize.BIGINT
    }
  },
  {
    indexes: [
      {
        name: 'unique_option_user_id',
        unique: true,
        fields: ['option_id', 'user_id']
      }
    ],
    sequelize,
    modelName: 'ballot',
    tableName: 'ballot'
  }
)

module.exports = ballot
